#include "fyt_msg/DetectorParam.h"
#include "ros/ros.h"
#include "std_msgs/String.h"

// static fyt_msg::DetectorParam detectorParam;
FILE *fp;

void detectorCallBack(const fyt_msg::DetectorParamConstPtr &msg){
    
    static uint8_t last_debug_value=0;
    if(msg->debug==last_debug_value) return;

    if(msg->debug==0){
        fp=freopen("runtime_msg.log","a",stdout); //重定向至文件
    }
    else {
        fp=freopen("/dev/tty","w",stdout); //重定向至控制台
        std::cin.clear();
    }

    last_debug_value=msg->debug;

}

void ioCallBack(const std_msgs::StringConstPtr &msg){
    ROS_INFO("%s",msg->data.c_str());
}

int main(int argc,char **argv){
    ros::init(argc,argv,"io_manage_node");
    ros::NodeHandle n;

    ros::Subscriber sub_detectorParam=n.subscribe("config_detector",1,detectorCallBack);
    ros::Subscriber sub_io_message=n.subscribe("send_info",5,ioCallBack);
    ros::spin();
}